{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "# 将list转换为字典"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "41e06d4a47d97157"
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'hammer': <__main__.Tool object at 0x10946f500>, 'screwdriver': <__main__.Tool object at 0x1094add90>, 'wrench': <__main__.Tool object at 0x1094ad520>}\n"
     ]
    }
   ],
   "source": [
    "class Tool:\n",
    "    def __init__(self, name):\n",
    "        self.name = name\n",
    "        \n",
    "tools = [Tool(\"hammer\"), Tool(\"screwdriver\"), Tool(\"wrench\")]\n",
    "\n",
    "tool_dict = {tool.name: tool for tool in tools}\n",
    "print(tool_dict)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-10-31T03:08:27.969414Z",
     "start_time": "2024-10-31T03:08:27.961981Z"
    }
   },
   "id": "adc4ea9727cf3f70",
   "execution_count": 2
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
